﻿<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>新建成员</title>
    <!--common-->
    <link rel="stylesheet" href="/resources/src/css/lib/bootstrap.min.css"/>
		<link rel="stylesheet" href="/resources/src/css/admin/main.css" />
</head>
<body>
<article class="main">
			<div class="main-wrapper">
				<section class="content">
					<div class="container">
						 <div class="con-header">
							
						</div>
						<div class="con-body">
							<div class="input-row clearfix">
								<label for="#userType" class="pull-left"><span>用户类型：</span></label>
								<div class="select pull-left">
									<select id="userType">
										<option class="option" value="0">请选择</option>
										<option value="4">管理员</option>
										<option value="1">机构账户</option>
										<option value="2">普通账户</option>
									</select>
								</div>
							</div>
							<div class="input-row">
								<label for="#name"><span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</span></label>
								<input type="text" id="name" name="name" placeholder="请输入姓名"/>
							</div>
							<div class="input-row">
								<label for="#email"><span>邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱：</span></label>
								<input type="text" id="email" name="email" placeholder="请输入邮箱"/>
							</div>
							<div class="input-row">
								<label for="#phone"><span>手&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机：</span></label>
								<input type="text" id="phone" name="phone" placeholder="请输入手机号"/>
							</div>
							<div class="input-row">
								<label for="#password"><span>初始密码：</span></label>
								<input type="password" id="password" name="password" placeholder="请输入初始密码"/>
							</div>	
							<div class="submit text-center">
								<p class="btn-text">
									<span id="c_user_submit">确认</span>
								</p>
							</div>
						</div> 
						<!-- 欢迎来到vcsaas后台管理系统 -->
					</div>
				</section>
			</div>
		</article>
    <script src="/resources/src/js/jquery-1.9.1.min.js"></script>
    <script src="/resources/src/js/jquery.nicescroll.js"></script>  
    <script src="/resources/src/js/jquery.validate.min.js"></script>
    <script src="/resources/src/js/messages_zh.js"></script>  
    <script src="/resources/src/js/main.js"></script>
    <script>
        $("#totalEdit").validate({
            debug:true,
            rules: {
              total_edit_phone:{
                required:true,
                isPhone:true
              },
              total_edit_email:{
                required:true,
                email:true
              }
            },
            messages: {
               total_edit_phone:{
                 required: "请输入手机",
                 isPhone:'请输入正确的手机'
               },
               total_edit_email:{
                 required: "请输入邮箱",
                 email:'请输入正确的邮箱'
               }
            },
            submitHandler:function(form){
                alert("fsdfds");
            }
        });
        jQuery.validator.addMethod("isPhone", function(value, element) {
            var phone = new RegExp(/^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/);
            return this.optional(element) || (phone.test(value));
        }, "请填写正确的手机号码");
        
       $(function(){
        	$("#c_user_submit").click(function(){
        		 var type = $("#userType option:selected").val();  
        		 var userName = $("#name").val();
        		 var phone = $("#phone").val();
        		 var email = $("#email").val();
        		 var password = $("#password").val();
        		 
        		 if(phone == '' || phone == null) {
        			 alert("请输入手机号码");
        			 return false;
        		 }
        		 if(password == '' || password == null) {
        			 alert("请输入密码");
        			 return false;
        		 }
        		 
        		 $.ajax({
     				type : "post",
     				url : "/admin/user/addUser",
     				data : {
     					"type" : type,
     					"userName" : userName,
     					"phone" : phone,
     					"email" : email,
     					"password" : password
     				},
     				dataType : "json",
     				success : function(data) {
     					if (data.status == true) {
     						alert(data.data);
     						location.href='/admin/user/list';
     					} else {
     						alert(data.data);
     						location.href='/admin/user/list';
     					}
     				}
     			})
        	})
        })
    </script>
    
</body>
</html>